require(["jquery","cookie"], function($){
	$.cookie.json = true;
	// 异步加载头部静态HTML资源
	$.ajax("/html/include/header.html").done(function(data){
		// 将HTML字符串添加到 <header> 标签内部
		$(".header").html(data);
	}).then(function(){
		let loginUser = $.cookie("login_user");
		// loginUser=JSON.parse(loginUser);
		if(loginUser){
			$(".bi_links .re").html(loginUser["email"]);
			$(".bi_links .lo").html("注销");
			$(".bi_links .lo").click(function(){
				$.removeCookie("login_user");
				location.reload();
			})
		}

	}).then(function(){
		const products = $.cookie("products") || [];
		const totalAmount = products.reduce(function(sum, curr){
		return sum += curr.amount;
		}, 0);
		$(".bi_links li:nth-child(4) span").text(totalAmount);
	})
	
});